package ru.ipo.dces.plugins;

import javax.swing.*;

import info.clearthought.layout.TableLayout;
import ru.ipo.dces.pluginapi.Plugin;
import ru.ipo.dces.pluginapi.PluginEnvironment;

public class PluginInt implements Plugin {

    private JPanel mapanel = null;
    static PluginEnvironment pe;

    public PluginInt(PluginEnvironment pe) {
        PluginInt.pe = pe;
    }

    public void activate() {
    }

    public void deactivate() {
    }

    public JPanel getPanel() {

        if (mapanel == null) {
            mapanel = new JPanel();

            TableLayout layout = new TableLayout(
                    new double[]{TableLayout.FILL},
                    new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL}
            );

            mapanel.setLayout(layout);

            //get statement panel and set its preferred size to be not very wide
            JComponent statementPanel = pe.getStatementPanel();
            /*Dimension statementPreferredSize = statementPanel.getPreferredSize();
            statementPanel.setPreferredSize(
                    new Dimension(
                            statementPreferredSize.width,
                            100//Math.min(statementPreferredSize.height, 200)
                    )
            );*/

            mapanel.add(new MathkitAppletPanel(), "0 2");
            mapanel.add(new JLabel("Условие:"), "0 0");
            mapanel.add(statementPanel, "0 1");
        }
        return mapanel;
    }

}